unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,XMLIntf,XMLDoc,Dialog_View;

type
  TC3DES_ENCRYPT=function (I,J:PChar):PChar;stdcall;//DO NOT FORGET STDCALL
  TC3DES_DECRYPT=function (I,J:PChar):PChar;stdcall;//DO NOT FORGET STDCALL  
  
  TForm1 = class(TDialogView)
    Btnx_1: TButton;
    Btnx_2: TButton;
    Btnx_3: TButton;
    procedure Btnx_3Click(Sender: TObject);
  private
  public
    function  GetKeyOrigin:string;
    function  GetTxtOrigin:string;
  end;

  function C3DES_ENCRYPT(I,J:PChar):PChar;stdcall;external 'STD3DES.dll' name '_C3DES_ENCRYPT@8';
  function C3DES_DECRYPT(I,J:PChar):PChar;stdcall;external 'STD3DES.dll' name '_C3DES_DECRYPT@8';
var
  Form1: TForm1;

implementation

uses
  Class_KzUtils,Class_KzDebug,Util_UTF8,Base64Unit;

{$R *.dfm}

procedure TForm1.Btnx_3Click(Sender: TObject);
var
  Handle:THandle;
  KeyOrigin:PAnsiChar;
  TxtOrigin:PAnsiChar;
  OutOrigin:PAnsiChar;
  DllName:string;  
  ENCRYPT:TC3DES_ENCRYPT;
begin
  DllName:='STD3DES.dll';
  //KeyOrigin:=PAnsiChar('ThisIsSpartaThisIsSparta');
  KeyOrigin:=PAnsiChar(GetKeyOrigin);
  TxtOrigin:=PAnsiChar(GetTxtOrigin);
  

  Handle:=LoadLibrary(PChar(DllName));
  if Handle <> 0 then
  begin
     @ENCRYPT := GetProcAddress(Handle,'_C3DES_ENCRYPT@8');
     if @ENCRYPT<>nil then
     begin
       OutOrigin:=ENCRYPT(KeyOrigin,TxtOrigin);
       KzDebug.FileFmt('CENCRTPY:%S',[OutOrigin]);
       OutOrigin:=C3DES_ENCRYPT(KeyOrigin,TxtOrigin);
       KzDebug.FileFmt('CENCRTPY:%S',[OutOrigin]);
     end;
  end;
end;

function TForm1.GetKeyOrigin: string;
var
  List:TStringList;
begin
  try
    List:=TStringList.Create;
    List.LoadFromFile('c:\cdh.key');
    Result:=Trim(List.Text);
    //Result:=Copy(Result,1,Length(Result));
  finally
    FreeAndNil(List);
  end;
end;

function TForm1.GetTxtOrigin: string;
var
  XMLDOC:IXMLDocument;
begin
  try
    XMLDOC:=NewXMLDocument();
    XMLDOC.LoadFromFile('c:\writ1001.xml');
    Result:=XMLDOC.XML.Text;
  finally
  end;
end;

end.
